package cn.itcast.dubbo.controller;

import cn.itcast.dubbo.pojo.Employee;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author Hujf
 * @title: UrlController
 * @description: TODO
 * @date 2020/7/22 0022下午 12:03
 */
@Controller
public class UrlController {
    @GetMapping(value = "/")
    public String toLogin() {
        return "login";
    }

    @GetMapping(value = "provider")
    public String toProvider(){
        return "provider";
    }

    @GetMapping(value = "type")
    public String type(){
        return "goods/type";
    }

    @GetMapping(value = "goodInfo")
    public String info(){
        return "goods/info";
    }

    @GetMapping(value = "warehouse")
    public String warehouse(){
        return "warehouse";
    }

    @GetMapping(value = "/order")
    public String order() {
        return "order";
    }

    @GetMapping(value = "/isLogin")
    @ResponseBody
    public Employee isLogin(HttpServletRequest request) {
        HttpSession session = request.getSession();
        return (Employee) session.getAttribute("emp");
    }

    @GetMapping(value = "/logout")
    public String logout(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Employee employee = (Employee) session.getAttribute("emp");
        if (employee != null) {
            session.removeAttribute("user");
            session.invalidate();
        }
        return "redirect:/";
    }

}
